/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Modelo;

import org.jgap.*;


/**
 *
 * @author ivyduk
 */
public class MinimizingQRFitnessFunction extends FitnessFunction{

   
    public MinimizingQRFitnessFunction(double[] costos,int[]demandas,int[] satisf,int numart){
        C1=costos[0];
        C2=costos[1];
        C3=costos[2];   
        C4=costos[3];
        C5=costos[4];
        
        D1=demandas[0];
        D2=demandas[1];
        D3=demandas[2];
        D4=demandas[3];
        D5=demandas[4];
    
        S1=satisf[0];
        S2=satisf[1];
        S3=satisf[2];
        S4=satisf[3];
        S5=satisf[4];
        
        numarticulos=numart;
    }
    private int numarticulos;
    private double frecuenciapedidos;
    private double porcentajesatisfaccion;
    private double C1;
    private double C2;
    private double C3;
    private double C4;
    private double C5;
    private int Qi;
    private int D1;
    private int D2;
    private int D3;
    private int D4;
    private int D5;
    private int DT=D1+D2+D3+D4+D5;
    private int S1;
    private int S2;
    private int S3;
    private int S4;
    private int S5;
    private double fitness;
    private int E1;
    private int E2;
    private int E3;
    private int E4;
    private int E5;
    

    
    public double NivelSatsifaccion(){
        double S;
        S=(1/DT)*((D1*S1)+(D2*S2)+(D3*S3)+(D4+S4)+(D5+S5));
        return S;
    }
    
    @Override
    protected double evaluate(IChromosome iC) {
    double F;

        /*F=(1/numarticulos)*((D1/(Integer)iC.getGene(0).getAllele())+
                            (D2/(Integer)iC.getGene(2).getAllele())+
                            (D3/(Integer)iC.getGene(4).getAllele())+
                            (D4/(Integer)iC.getGene(6).getAllele())+
                            (D5/(Integer)iC.getGene(8).getAllele()));*/
         
         fitness=Math.round(C1*(((Integer)iC.getGene(0).getAllele()+1)/2)+
                                 (Integer)iC.getGene(1).getAllele()-E1+
                            C2*(((Integer)iC.getGene(2).getAllele()+1)/2)+
                                 (Integer)iC.getGene(3).getAllele()-E2+
                            C3*(((Integer)iC.getGene(4).getAllele()+1)/2)+
                                 (Integer)iC.getGene(5).getAllele()-E3+
                            C4*(((Integer)iC.getGene(6).getAllele()+1)/2)+
                                 (Integer)iC.getGene(7).getAllele()-E4+
                            C5*(((Integer)iC.getGene(0).getAllele()+1)/2)+
                                 (Integer)iC.getGene(1).getAllele()-E5);

          return fitness;
    }
    
    
    
}
